import Vue from 'vue'
Vue.filter('textcell',function(v){
	if(v.length>=15){
		return v.substr(0,15)+'...'
	}else{
		return v
	}
})
export default {
	uploadImg(e){
		return new Promise((reject,resolve)=>{
			var reader = new FileReader();
			reader.readAsDataURL(e.target.files[0]);
			reader.onload = function(e){
				let img = new Image();
				img.src = e.target.result;
				img.onload = function(){
					let canvas = document.createElement("canvas");
					let ctx = canvas.getContext("2d");
					let initSize = img.src.length;
					let width = img.width;
					let height = img.height;
					canvas.width = width;
					canvas.height = height;
					ctx.fillStyle = "#fff";
					ctx.fillRect(0, 0, canvas.width, canvas.height);
					ctx.drawImage(img, 0, 0, width, height);
					let ndata = canvas.toDataURL("image/jpeg", 0.1);
					let str = ndata.split(',')[1]
					reject({
						url:ndata,
						img:str
					})
				}
			}
		})
	}
}
